define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'zone/char/index' + location.search,
                    add_url: 'zone/char/add',
                    edit_url: 'zone/char/edit',
                    del_url: 'zone/char/del',
                    multi_url: 'zone/char/multi',
                    table: 'char',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'aid',
                sortName: 'aid',
                search:false,
                exportTypes:['excel'],
                columns: [
                    [
                        {checkbox: true},
                        {field: 'aid', title: __('Aid'),operate: false,visible: false},
                        {field: 'accname', title: __('Accname'),operate: 'LIKE %...%',placeholder:'模糊搜索'},
                        {field: 'charguid', title: __('Charguid'),operate: false,visible:false},
                        {field: 'charname', title: __('Charname'),operate: 'LIKE %...%',placeholder:'模糊搜索'},
                        {field: 'title', title: __('Title'),operate: false, visible: false},
                        {field: 'pw', title: __('Pw'),operate: false,visible:false},
                        {field: 'sex', title: __('Sex'),operate: false,searchList: {
                                "0":"男",
                                "1":"女",
                            },formatter:function (value,row,index) {
                                if (value ===0){return '<span class="label bg-red">女</span>';}
                                if (value ===1){return '<span class="label bg-aqua">男</span>';}
                            }},
                        {field: 'level', title: __('Level'),operate: false},
                        {field: 'enegry', title: __('Enegry'),operate: false,visible: false},
                        {field: 'energymax', title: __('Energymax'),operate: false,visible: false},
                        {field: 'outlook', title: __('Outlook'),operate: false,visible: false},
                        {field: 'scene', title: __('Scene'),operate: false,visible: false},
                        {field: 'xpos', title: __('Xpos'),operate: false,visible: false},
                        {field: 'zpos', title: __('Zpos'),operate: false,visible: false},
                        {field: 'menpai', title: __('Menpai'),operate: false,visible: false},
                        {field: 'hp', title: __('Hp'),operate: false,visible: false},
                        {field: 'mp', title: __('Mp'),operate: false,visible: false},
                        {field: 'strikepoint', title: __('Strikepoint'),operate: false,visible: false},
                        {field: 'str', title: __('Str'),operate: false,visible: false},
                        {field: 'spr', title: __('Spr'),operate: false,visible: false},
                        {field: 'con', title: __('Con'),operate: false,visible: false},
                        {field: 'ipr', title: __('Ipr'),operate: false,visible: false},
                        {field: 'dex', title: __('Dex'),operate: false,visible: false},
                        {field: 'points', title: __('Points'),operate: false,visible: false},
                        {field: 'logouttime', title: __('Logouttime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'logintime', title: __('Logintime'), operate: false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'haircolor', title: __('Haircolor'),operate: false,visible: false},
                        {field: 'hairmodel', title: __('Hairmodel'),operate: false,visible: false},
                        {field: 'facecolor', title: __('Facecolor'),operate: false,visible: false},
                        {field: 'facemodel', title: __('Facemodel'),operate: false,visible: false},
                        {field: 'vmoney', title: __('Vmoney'),operate: false,visible: false},
                        {field: 'isvalid', title: __('Isvalid'),operate: false,visible: false},
                        {field: 'exp', title: __('Exp'),operate: false,visible: false},
                        {field: 'dbversion', title: __('Dbversion'),operate: false,visible: false},
                        {field: 'carrypet', title: __('Carrypet'),operate: false,visible: false},
                        {field: 'guldid', title: __('Guldid'),operate: false,visible: false},
                        {field: 'teamid', title: __('Teamid'),operate: false,visible: false},
                        {field: 'headid', title: __('Headid'),operate: false,visible: false},
                        {field: 'erecover', title: __('Erecover'),operate: false,visible: false},
                        {field: 'vigor', title: __('Vigor'),operate: false,visible: false},
                        {field: 'maxvigor', title: __('Maxvigor'),operate: false,visible: false},
                        {field: 'vrecover', title: __('Vrecover'),operate: false,visible: false},
                        {field: 'pwdeltime', title: __('Pwdeltime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'bkscene', title: __('Bkscene'),operate: false,visible: false},
                        {field: 'bkxpos', title: __('Bkxpos'),operate: false,visible: false},
                        {field: 'bkzpos', title: __('Bkzpos'),operate: false,visible: false},
                        {field: 'dietime', title: __('Dietime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'bankmoney', title: __('Bankmoney'),operate: false,visible: false},
                        {field: 'bankend', title: __('Bankend'),operate: false,visible: false},
                        {field: 'rage', title: __('Rage'),operate: false,visible: false},
                        {field: 'reserve', title: __('Reserve'),operate: false,visible: false},
                        {field: 'dinfo', title: __('Dinfo'),operate: false,visible: false},
                        {field: 'defeq', title: __('Defeq'),operate: false,visible: false},
                        {field: 'guildpoint', title: __('Guildpoint'),operate: false, visible: false},
                        {field: 'menpaipoint', title: __('Menpaipoint'),operate: false,visible: false},
                        {field: 'gevil', title: __('Gevil'),operate: false,visible: false},
                        {field: 'pkvalue', title: __('Pkvalue'),operate: false,visible: false},
                        {field: 'otime', title: __('Otime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'deltime', title: __('Deltime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'expinfo', title: __('Expinfo'),operate: false,visible: false},
                        {field: 'savetime', title: __('Savetime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'crc32', title: __('Crc32'),operate: false,visible: false},
                        {field: 'loginip', title: __('Loginip'),operate: false,visible: false},
                        {field: 'pkvaluetime', title: __('Pkvaluetime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'fatigue', title: __('Fatigue'),operate: false,visible: false},
                        {field: 'yuanbao', title: __('Yuanbao'),operate:false,visible: false},
                        {field: 'isolditem', title: __('Isolditem'),operate: false,visible: false},
                        {field: 'uipoint', title: __('Uipoint'),operate: false,visible: false},
                        {field: 'zengdian', title: __('Zengdian'),operate: false,visible: false},
                        {
                            field: 'buttons',
                            title: '角色解封',
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'ajax',
                                    text: '角色解封',
                                    title: '角色解封',
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-play',
                                    url: 'offline/char/setCharNormal',
                                    confirm: '确定测试',
                                    success: function (data, ret) {
                                        Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});